package cn.yto.print.config;

import cn.yto.print.model.dto.PrintCacheDTO;
import cn.yto.print.model.response.PrintTaskResponse;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalCause;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Slf4j
public class CaffeineCacheConfig {

    private static final Cache<String, PrintCacheDTO> PRINT_CACHE = Caffeine.newBuilder()
            .initialCapacity(100).maximumSize(500).expireAfterWrite(10, TimeUnit.MINUTES).recordStats().build();
    private static final Cache<String, List<PrintTaskResponse>> EXPIRED_CACHE = Caffeine.newBuilder()
            .initialCapacity(10).maximumSize(50).expireAfterWrite(10, TimeUnit.MINUTES).recordStats().build();
    private static final Cache<String, Boolean> PROCESS_CACHE = Caffeine.newBuilder()
            .initialCapacity(10).maximumSize(10).expireAfterWrite(30, TimeUnit.SECONDS).build();
    private static final Cache<String, Integer> HEART_CACHE = Caffeine.newBuilder()
            .initialCapacity(10).maximumSize(10).expireAfterWrite(5, TimeUnit.MINUTES).build();

    public static Cache<String, PrintCacheDTO> getPrintCache() {
        return PRINT_CACHE;
    }

    public static Cache<String, List<PrintTaskResponse>> getExpiredCache() {
        return EXPIRED_CACHE;
    }

    public static Cache<String, Boolean> getProcessCache() {
        return PROCESS_CACHE;
    }

    public static Cache<String, Integer> getHeartCache() {
        return HEART_CACHE;
    }

}
